package server.handler.groupHandler;

import com.alibaba.fastjson.JSONObject;
import common.EnvelopeMessage;
import common.bodies.GroupShipBody;
import server.dao.GroupDao;
import server.dao.UserDao;
import server.handler.SimpleHandler;
import server.session.Session;

public class GroupMuteHandler implements SimpleHandler {
    @Override
    public void handle(EnvelopeMessage msg, Session session) {
        JSONObject body = msg.getBody();
        Integer groupId = body.getInteger("groupId");
        String memberName = body.getString("memberName");
        String groupName = body.getString("groupName");
        Boolean isMuted = body.getBoolean("muted");
        Integer memberId = new UserDao().getUserIdByUsername(memberName);
        GroupShipBody ship;
        if (isMuted){
            ship = new GroupShipBody(memberId, groupId, groupName, -1, 1);
        } else {
            ship = new GroupShipBody(memberId, groupId, groupName, 1, 1);
        }
        new GroupDao().updateGroupShip(ship);
    }
}
